package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: atguigu
 * @create: 2023-08-28 15:54
 */
@RestController
@RequestMapping("/admin/product")
//@CrossOrigin
public class BaseCategoryController {


    @Autowired
    private BaseCategory1Service baseCategory1Service;

    @Resource //先根据BeanId(对象名称)找对象；再根据类型
    private BaseCategory2Service baseCategory2Service;

    @Autowired
    private BaseCategory3Service baseCategory3Service;

    /**
     * 查询所有一级分类列表
     *
     * @return
     */
    @ApiOperation("查询所有一级分类列表")
    @GetMapping("/getCategory1")
    public Result getCategory1() {
        List<BaseCategory1> list = baseCategory1Service.getCategory1();
        return Result.ok(list);
    }

    /**
     * 查询指定一级分类下二级分类列表
     *
     * @param category1Id
     * @return
     */
    @ApiOperation("查询指定一级分类下二级分类列表")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") Long category1Id) {
        List<BaseCategory2> list = baseCategory2Service.getCategory2(category1Id);
        return Result.ok(list);
    }

    /**
     * 查询指定二级分类下三级分类列表
     *
     * @param category2Id
     * @return
     */
    @ApiOperation("查询指定二级分类下三级分类列表")
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3> list = baseCategory3Service.getCategory3(category2Id);
        return Result.ok(list);
    }
}
